home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: The Amorphous Mass <robinson@blue.weeg.uiowa.edu>
- Newsgroups: comp.lang.c.moderated,comp.lang.c
- Subject: Re: fflush(stdin) - not guaranteed to work?
- Date: 17 Apr 1996 10:44:10 -0500
- Organization: University of Iowa, Iowa City, IA, USA
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4l33ka$7n0@solutions.solon.com>
- References: <4ksjpn$rjt@solutions.solon.com> <4ku3id$53h@solutions.solon.com> <4l1idn$pvs@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
- X-Sender: robinson@green.weeg.uiowa.edu
-
- On 16 Apr 1996, News User Id wrote:
- > To the implicit followon question, "If
- > fflush(stdin) won't work, how *can* I flush the user's typeahead
- > before issuing a prompt confirming whether I should reformat the
- > hard drive?", the FAQ list suggests no answer, because I don't
- > know a good one (other than, your program probably shouldn't be
- > offering to do that at all).
-
- Since you offer answers to questions that might work on most
- implementations (eg the definition of the offsetof() macro) you might
- suggest a variation on
-
- void Flush()
- {
- while(getchar() != '\n')
- ;
- }
-
- which is only called if the last character read was not a newline.
- This has yet to fail on the systems I've tested it on, but that obviously
- doesn't mean that it always works. Can anyone get it to fail to
- transparently clear stdin (by, say, requuiring that the user hit <CR>)?
- Remember to only call it if the last character read was not a newline. :-)
-
- --
- James Robinson "Because we are returning a copy for postfix ++
- james-robinson@uiowa.edu expressions, statements such as (c++)++; won't
- robinson@cs.uiowa.edu work as expected." -- Weiskamp & Flamig,
- _The_Complete_C++_Primer_, 2nd ed.
-